home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 267_01 / as6.h < prev    next >
Text File  |  1989-01-11  |  12KB  |  399 lines

  1. /*
  2.     HEADER:        CUG267;
  3.     TITLE:        S6 Cross-Assembler (Portable);
  4.     FILENAME:    AS6.H;
  5.     VERSION:    0.2;
  6.     DATE:        08/27/1988;
  7.  
  8.     DESCRIPTION:    "This program lets you use your computer to assemble
  9.             code for the SGS S6 family of microprocessors.  The
  10.             program is written in portable C rather than BDS C.
  11.             All assembler features are supported except relocation
  12.             linkage, and macros.";
  13.  
  14.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  15.             SGS, S6 family;
  16.  
  17.     SYSTEM:        CP/M-80, CP/M-86, HP-UX, MSDOS, PCDOS, QNIX;
  18.     COMPILERS:    Aztec C86, Aztec CII, CI-C86, Eco-C, Eco-C88, HP-UX,
  19.             Lattice C, Microsoft C,    QNIX C;
  20.  
  21.     WARNINGS:    "This program is written in as portable C as possible.
  22.             A port to BDS C would be extremely difficult.  A port
  23.             to Toolworks C is untried."
  24.  
  25.     AUTHORS:    William C. Colley III;
  26. */
  27.  
  28. /*
  29.                S6 Cross-Assembler in Portable C
  30.  
  31.         Copyright (c) 1986, 1987 William C. Colley, III
  32.  
  33. Revision History:
  34.  
  35. Ver    Date        Description
  36.  
  37. 0.0    NOV 1987    Derived from my 6502 cross-assembler.  WCC3.
  38.  
  39. 0.1    JUNE 1988    Fixed glitches in the relative jumps and in the bit
  40.             operations to make the assembler conform to the
  41.             machine rather than to the machine's documentation.
  42.             WCC3.
  43.  
  44. 0.2    AUG 1988    Fixed a bug in the command line parser that puts it
  45.             into a VERY long loop if the user types a command line
  46.             like "AS6 FILE.ASM -L".  WCC3 per Alex Cameron.
  47.  
  48. This header file contains the global constants and data type definitions for
  49. all modules of the cross-assembler.  This also seems a good place to put the
  50. compilation and linkage instructions for the animal.  This list currently
  51. includes the following compilers:
  52.  
  53.         Compiler Name        Op. Sys.    Processor
  54.  
  55.     1)  Aztec C86            CP/M-86        8086, 8088
  56.                     MSDOS/PCDOS
  57.  
  58.     2)  AZTEC C II            CP/M-80        8080, Z-80
  59.  
  60.     3)  Computer Innovations C86    MSDOS/PCDOS    8086, 8088
  61.  
  62.     4)  Eco-C            CP/M-80        Z-80
  63.  
  64.     5)  Eco-C88            MSDOS/PCDOS    8086, 8088
  65.  
  66.     6)  HP C            HP-UX        68000
  67.  
  68.     7)  Lattice C            MSDOS/PCDOS    8086, 8088
  69.  
  70.     8)  Microsoft C            MSDOS/PCDOS    8086, 8088
  71.  
  72.     9)  QNIX C            QNIX        8086, 8088
  73.  
  74. Further additions will be made to the list as users feed the information to
  75. me.  This particularly applies to UNIX and IBM-PC compilers.
  76.  
  77. Compile-assemble-link instructions for this program under various compilers
  78. and operating systems:
  79.  
  80.     1)    Aztec C86:
  81.  
  82.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  83.         other compiler names in AS6.H.
  84.  
  85.     B)  Assuming that all files are on drive A:, run the following
  86.         sequence of command lines:
  87.  
  88.         A>cc as6
  89.         A>cc as6eval
  90.         A>cc as6util
  91.         A>ln as6.o as6eval.o as6util.o -lc
  92.         A>era as6*.o
  93.  
  94.     2)  Aztec CII (version 1.06B):
  95.  
  96.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  97.         other compiler names in AS6.H.
  98.  
  99.     B)  Assuming the C compiler is called "CC.COM" and all files are
  100.         on drive A:, run the following sequence of command lines:
  101.  
  102.         A>cc as6
  103.         A>as -zap as6
  104.         A>cc as6eval
  105.         A>as -zap as6eval
  106.         A>cc as6util
  107.         A>as -zap as6util
  108.         A>ln as6.o as6eval.o as6util.o -lc
  109.         A>era as6*.o
  110.  
  111.     3)  Computer Innovations C86:
  112.  
  113.     A)  Uncomment out the "#define CI_C86 1" line and comment out all
  114.         other compiler names in AS6.H.
  115.  
  116.     B)  Compile the files AS6.C, AS6EVAL.C, and AS6UTIL.C.  Link
  117.         according to instructions that come with the compiler.
  118.  
  119.     4)  Eco-C (CP/M-80 version 3.10):
  120.  
  121.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  122.         other compiler names in AS6.H.
  123.  
  124.     B)  Assuming all files are on drive A:, run the following sequence of
  125.         command lines:
  126.  
  127.         A>cp as6 -i -m
  128.         A>cp as6eval -i -m
  129.         A>cp as6util -i -m
  130.         A>l80 as6,as6eval,as6util,as6/n/e
  131.         A>era as6*.mac
  132.         A>era as6*.rel
  133.  
  134.     5)  Eco-C88:
  135.  
  136.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  137.         other compiler names in AS6.H.
  138.  
  139.     B)  Compile the files AS6.C, AS6EVAL.C, and AS6UTIL.C.  Link
  140.         according to instructions that come with the compiler.
  141.  
  142.     6)  HP-UX (a UNIX look-alike running on an HP-9000 Series 200/500,
  143.     68000-based machine):
  144.  
  145.     A)  Uncomment out the "#define HP_UX 1" line and comment out all
  146.         other compiler names in AS6.H.
  147.  
  148.     B)  Run the following command line:
  149.  
  150.         . cc as6.c as6eval.c as6util.c
  151.  
  152.     7)  Lattice C:
  153.  
  154.     A)  Uncomment out the "#define LATTICE_C 1" line and comment out all
  155.         other compiler names in AS6.H.
  156.  
  157.     B)  Compile the files AS6.C, AS6EVAL.C, and AS6UTIL.C.  Link
  158.         according to instructions that come with the compiler.
  159.  
  160.     8)  Microsoft C (version 3.00):
  161.  
  162.     A)  Uncomment out the "#define MICROSOFT_C 1" line and comment out
  163.         all other compiler names in AS6.H.
  164.  
  165.     B)  Run the following command line:
  166.  
  167.         C>cl as6.c as6eval.c as6util.c
  168.  
  169.     9)    QNIX C:
  170.  
  171.     A)  Uncomment out the "#define QNIX 1" line and comment out all other
  172.         compiler names in AS6.H.
  173.  
  174.     B)  Run the following command line:
  175.  
  176.         . cc as6.c as6eval.c as6util.c
  177.  
  178. Note that, under CP/M-80, you can't re-execute a core image from a previous
  179. assembly run with the "@.COM" trick.  This technique is incompatible with the
  180. Aztec CII compiler, so I didn't bother to support it at all.
  181. */
  182.  
  183. #include <stdio.h>
  184.  
  185. /*  Comment out all but the line containing the name of your compiler:    */
  186.  
  187. #define        AZTEC_C        1
  188. /* #define    CI_C86        1                    */
  189. /* #define    ECO_C        1                    */
  190. /* #define    HP_UX        1                    */
  191. /* #define    LATTICE_C    1                    */
  192. /* #define    MICROSOFT_C    1                    */
  193. /* #define    QNIX        1                    */
  194.  
  195. /*  Compiler dependencies:                        */
  196.  
  197. #ifdef    AZTEC_C
  198. #define    getc(f)        agetc(f)
  199. #define    putc(c,f)    aputc(c,f)
  200. #endif
  201.  
  202. #ifndef    ECO_C
  203. #define    FALSE        0
  204. #define    TRUE        (!0)
  205. #endif
  206.  
  207. #ifdef    LATTICE_C
  208. #define    void        int
  209. #endif
  210.  
  211. #ifdef    QNIX
  212. #define    fprintf        tfprintf
  213. #define    printf        tprintf
  214. #endif
  215.  
  216. /*  On 8-bit machines, the static type is as efficient as the register    */
  217. /*  type and far more efficient than the auto type.  On larger machines    */
  218. /*  such as the 8086 family, this is not necessarily the case.  To    */
  219. /*  let you experiment to see what generates the fastest, smallest code    */
  220. /*  for your machine, I have declared internal scratch variables in    */
  221. /*  functions "SCRATCH int", "SCRATCH unsigned", etc.  A SCRATCH    */
  222. /*  varible is made static below, but you might want to try register    */
  223. /*  instead.                                */
  224.  
  225. #define    SCRATCH        static
  226.  
  227. /*  A slow, but portable way of cracking an unsigned into its various    */
  228. /*  component parts:                            */
  229.  
  230. #define    clamp(u)    ((u) &= 0xffff)
  231. #define    high(u)        (((u) >> 8) & 0xff)
  232. #define    low(u)        ((u) & 0xff)
  233. #define    word(u)        ((u) & 0xffff)
  234.  
  235. /*  The longest source line the assembler can hold without exploding:    */
  236.  
  237. #define    MAXLINE        255
  238.  
  239. /*  The maximum number of source files that can be open simultaneously:    */
  240.  
  241. #define    FILES        4
  242.  
  243. /*  The fatal error messages generated by the assembler:        */
  244.  
  245. #define    ASMOPEN        "Source File Did Not Open"
  246. #define    ASMREAD        "Error Reading Source File"
  247. #define    DSKFULL        "Disk or Directory Full"
  248. #define    FLOFLOW        "File Stack Overflow"
  249. #define    HEXOPEN        "Object File Did Not Open"
  250. #define    IFOFLOW        "If Stack Overflow"
  251. #define    LSTOPEN        "Listing File Did Not Open"
  252. #define    NOASM        "No Source File Specified"
  253. #define    SYMBOLS        "Too Many Symbols"
  254.  
  255. /*  The warning messages generated by the assembler:            */
  256.  
  257. #define    BADOPT        "Illegal Option Ignored"
  258. #define    NOHEX        "-o Option Ignored -- No File Name"
  259. #define    NOLST        "-l Option Ignored -- No File Name"
  260. #define    TWOASM        "Extra Source File Ignored"
  261. #define    TWOHEX        "Extra Object File Ignored"
  262. #define    TWOLST        "Extra Listing File Ignored"
  263.  
  264. /*  Line assembler (AS6.C) constants:                    */
  265.  
  266. #define    BIGINST        3        /*  longest instruction length    */
  267. #define    IFDEPTH        16        /*  maximum IF nesting level    */
  268. #define    NOP        0x04        /*  processor's NOP opcode    */
  269. #define    ON        1        /*  assembly turned on        */
  270. #define    OFF        -1        /*  assembly turned off        */
  271.  
  272. /*  Line assembler (AS6.C) opcode attribute word flag masks:        */
  273.  
  274. #define    PSEUDO        0400    /*  is pseudo op            */
  275. #define    ISIF        0200    /*  is IF, ELSE, or ENDIF        */
  276.  
  277. /*  Line assembler (AS6.C) pseudo-op opcode token values:        */
  278.  
  279. #define    DB        1
  280. #define    DS        2
  281. #define    DW        3
  282. #define    ELSE        4
  283. #d